import axios from "axios";
import { Message } from "antd";
// 封装ajax，查看github怎么使用axios（https://github.com/search?q=axios）
export default function ajax(url, data = {}, type = "GET") {
  return new Promise((resolve, reject) => {
    let promise;
    if (type === "GET") {
      promise = axios.get(url, {
        params: data
      });
    } else {
      promise = axios.post(url, data);
    }
    promise
      .then(res => {
        resolve(res);
      })
      .catch(err => {
        Message.error("请求出错了：" + err.message);
      });
  });
}

console.log("axios......");

let getList = async () => {
  let res = await ajax(
    "https://www.easy-mock.com/mock/5cf8cb4e54abff3ee041a142/example/goodslist",
    {},
    "GET"
  );
  console.log(res.data.data);
};

getList();
